﻿using HandyControl.Controls;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi.Views.PlcView
{
    /// <summary>
    /// InBoxTakeView.xaml 的交互逻辑入库取料点位页面
    /// </summary>
    public partial class InBoxTakeView : UserControlBase
    {
        
        public InBoxTakeView()
        {
            InitializeComponent();
        }
        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;

            LoadTask();
        }

        private void LoadTask()
        {
            var ioi = LocalStatic.Plc.Read<Int16>("1082");
            if (ioi.IsSucceed==false)
            {
                TextBoxMoCode1g1.Text = "未接收";
            }
            else
            {
                TextBoxMoCode1g1.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("1083");
            if (ioi.IsSucceed == false)
            {
                TextBoxMoCode1g2.Text = "未接收";
            }
            else
            {
                TextBoxMoCode1g2.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("1084");
            if (ioi.IsSucceed == false)
            {
                TextBoxMoCode1g3.Text = "未接收";
            }
            else
            {
                TextBoxMoCode1g3.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("1085");
            if (ioi.IsSucceed == false)
            {
                TextBoxMoCode1g4.Text = "未接收";
            }
            else
            {
                TextBoxMoCode1g4.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("1086");
            if (ioi.IsSucceed == false)
            {
                TextBoxMoCode1g5.Text = "未接收";
            }
            else
            {
                TextBoxMoCode1g5.Text = ioi.Value.ToString();
            }
            var ioi1 = LocalStatic.Plc.Read<float>("1242");
            if (ioi1.IsSucceed == false)
            {
                TextBoxMoCode2g1.Text = "未接收";
            }
            else
            {
                TextBoxMoCode2g1.Text = ioi1.Value.ToString();
            }
            ioi1 = LocalStatic.Plc.Read<float>("1168");
            if (ioi1.IsSucceed == false)
            {
                TextBoxMoCode2g2.Text = "未接收";
            }
            else
            {
                TextBoxMoCode2g2.Text = ioi1.Value.ToString();
            }
            ioi1 = LocalStatic.Plc.Read<float>("1170");
            if (ioi1.IsSucceed == false)
            {
                TextBoxMoCode2g3.Text = "未接收";
            }
            else
            {
                TextBoxMoCode2g3.Text = ioi1.Value.ToString();
            }
            ioi1 = LocalStatic.Plc.Read<float>("1172");
            if (ioi1.IsSucceed == false)
            {
                TextBoxMoCode2g4.Text = "未接收";
            }
            else
            {
                TextBoxMoCode2g4.Text = ioi1.Value.ToString();
            }
            ioi1 = LocalStatic.Plc.Read<float>("1186");
            if (ioi1.IsSucceed == false)
            {
                TextBoxMoCode2g5.Text = "未接收";
            }
            else
            {
                TextBoxMoCode2g5.Text = ioi1.Value.ToString();
            }
            ioi1 = LocalStatic.Plc.Read<float>("1188");
            if (ioi1.IsSucceed == false)
            {
                TextBoxMoCode2g6.Text = "未接收";
            }
            else
            {
                TextBoxMoCode2g6.Text = ioi1.Value.ToString();
            }
            ioi1 = LocalStatic.Plc.Read<float>("1222");
            if (ioi1.IsSucceed == false)
            {
                TextBoxMoCode2g7.Text = "未接收";
            }
            else
            {
                TextBoxMoCode2g7.Text = ioi1.Value.ToString();
            }
            //TextBoxMoCode1g1.Text = LocalStatic.Plc.Read<Int16>("1082").Value.ToString();
            //TextBoxMoCode1g2.Text = LocalStatic.Plc.Read<Int16>("1083").Value.ToString();
            //TextBoxMoCode1g3.Text = LocalStatic.Plc.Read<Int16>("1084").Value.ToString();
            //TextBoxMoCode1g4.Text = LocalStatic.Plc.Read<Int16>("1085").Value.ToString();
            //TextBoxMoCode1g5.Text = LocalStatic.Plc.Read<Int16>("1086").Value.ToString();
            //TextBoxMoCode2g1.Text = LocalStatic.Plc.Read<float>("1242").Value.ToString();
            //TextBoxMoCode2g2.Text = LocalStatic.Plc.Read<float>("1168").Value.ToString();
            //TextBoxMoCode2g3.Text = LocalStatic.Plc.Read<float>("1170").Value.ToString();
            //TextBoxMoCode2g4.Text = LocalStatic.Plc.Read<float>("1172").Value.ToString();
            //TextBoxMoCode2g5.Text = LocalStatic.Plc.Read<float>("1186").Value.ToString();
            //TextBoxMoCode2g6.Text = LocalStatic.Plc.Read<float>("1188").Value.ToString();
            //TextBoxMoCode2g7.Text = LocalStatic.Plc.Read<float>("1222").Value.ToString();
        }

        private void Label_MouseDoubleClick1g1(object sender, MouseButtonEventArgs e)
        {
            try
            {
                short ser = Convert.ToInt16(TextBoxMoCode1g1.Text);
                var ioi=  LocalStatic.Plc.Write<Int16>("1082", ser);
                if (ioi.IsSucceed==true)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            LoadTask();
        }

        private void Label_MouseDoubleClick1g2(object sender, MouseButtonEventArgs e)
        {
            try
            {
                short ser = Convert.ToInt16(TextBoxMoCode1g2.Text);
                var ioi = LocalStatic.Plc.Write<Int16>("1083", ser);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }           
        private void Label_MouseDoubleClick1g3(object sender, MouseButtonEventArgs e)
        {
            try
            {
                short ser = Convert.ToInt16(TextBoxMoCode1g3.Text);
                var ioi = LocalStatic.Plc.Write<Int16>("1084", ser);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
        private void Label_MouseDoubleClick1g4(object sender, MouseButtonEventArgs e)
        {
            try
            {
                short ser = Convert.ToInt16(TextBoxMoCode1g4.Text);
                var ioi = LocalStatic.Plc.Write<Int16>("1085", ser);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_MouseDoubleClick1g5(object sender, MouseButtonEventArgs e)
        {
            try
            {
                short ser = Convert.ToInt16(TextBoxMoCode1g5.Text);
                var ioi = LocalStatic.Plc.Write<Int16>("1086", ser);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_MouseDoubleClick2g1(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(TextBoxMoCode2g1.Text);
                var ioi = LocalStatic.Plc.Write<float>("1242", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_MouseDoubleClick2g2(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(TextBoxMoCode2g2.Text);
                var ioi = LocalStatic.Plc.Write<float>("1168", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
            
        }

        private void Label_MouseDoubleClick2g3(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(TextBoxMoCode2g3.Text);
                var ioi = LocalStatic.Plc.Write<float>("1170", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_MouseDoubleClick2g4(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(TextBoxMoCode2g4.Text);
                var ioi = LocalStatic.Plc.Write<float>("1172", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_MouseDoubleClick2g5(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(TextBoxMoCode2g5.Text);
                var ioi = LocalStatic.Plc.Write<float>("1186", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }

        }

        private void Label_MouseDoubleClick2g6(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(TextBoxMoCode2g6.Text);
                var ioi = LocalStatic.Plc.Write<float>("1188", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_MouseDoubleClick2g7(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(TextBoxMoCode2g7.Text);
                var ioi = LocalStatic.Plc.Write<float>("1222", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

    }
}
